package util;

import java.util.StringTokenizer;

import javax.servlet.http.Cookie;

public class CookieUtil {
	
	public static Cookie makeCookie(String mail, String salt) {
		StringBuffer sb = new StringBuffer();
		sb.append(mail);
		sb.append('|');
		sb.append(EncryptUtil.makeHashed(mail, salt));
		return new Cookie("mail", sb.toString());
		
	}
	
	public static Boolean verifyCookie(Cookie c, String salt) {
		StringTokenizer st = new StringTokenizer(c.getValue(), "|");
		if(st.countTokens() != 2) {
			return false;
		}
		String mail = st.nextToken();
		String hashedMail = st.nextToken();
		return hashedMail.equals(EncryptUtil.makeHashed(mail, salt));
	}
}
